package com.cos.lession59.web.controller;

import org.springframework.security.access.annotation.Secured;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * @author: COS
 * @time: 2022/3/14 9:04
 * @description:
 */
@Controller
@RequestMapping("/user")
public class UserController {
    @RequestMapping("/hello")
    public String hello(){
        System.out.println("hello");
        Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
        //获取登录用户名
        System.out.println(authentication.getName());
        return "index";
    }

    @RequestMapping("/getAll")
    @Secured({"ROLE_USER","ROLE_ADMIN"})
    public String getAll(){
        System.out.println("getAll");
        return "";
    }
    @RequestMapping("/addUser")
    @Secured("ROLE_USER")
    public String addUser(){
        System.out.println("addUser");
        return "";
    }
    @RequestMapping("/delUser")
    @Secured("ROLE_ADMIN")
    public String delUser(){
        System.out.println("delUser");
        return "";
    }


}
